//package com.mediacloud.app.newsmodule.fragment.imagetext
//
//import android.annotation.SuppressLint
//import android.content.Intent
//import android.content.IntentFilter
//import android.os.AsyncTask
//import android.text.TextUtils
//import android.util.Log
//import android.util.TypedValue
//import android.view.View
//import android.view.View.OnTouchListener
//import android.webkit.WebSettings
//import androidx.core.widget.NestedScrollView
//import com.mediacloud.app.appfactory.cache.AppConfig
//import com.mediacloud.app.model.eventbus.control.NormalNewsDetailControl
//import com.mediacloud.app.model.fragment.BaseFragment
//import com.mediacloud.app.model.interfaces.DataInvokeCallBack
//import com.mediacloud.app.model.news.ArticleItem
//import com.mediacloud.app.model.news.ArticleItemReciver
//import com.mediacloud.app.model.news.CatalogItem
//import com.mediacloud.app.model.news.ShowSwitch
//import com.mediacloud.app.model.view.WebBrowser
//import com.mediacloud.app.newsmodule.R
//import com.mediacloud.app.newsmodule.activity.ImageTextDetailActivity
//import com.mediacloud.app.newsmodule.addnewslike.m.AddLikeDataInvoke
//import com.mediacloud.app.newsmodule.addnewslike.p.NewsLikePresenter
//import com.mediacloud.app.newsmodule.addnewslike.v.ILikesNumUpdate
//import com.mediacloud.app.newsmodule.broadcast.PowerStateReciver
//import com.mediacloud.app.newsmodule.fragment.imagetext.ImageTextDetailFragment.ParseHTMLDataTask
//import com.mediacloud.app.newsmodule.fragment.webview.WebViewFragment
//import com.mediacloud.app.newsmodule.javascript.H5PayJavaScriptInterface
//import com.mediacloud.app.newsmodule.pay.GiveMoneyDialog.GivenMoneyStatus
//import com.mediacloud.app.newsmodule.utils.AppfacBuyEnableUtils
//import com.mediacloud.app.newsmodule.utils.CollectionController
//import com.mediacloud.app.newsmodule.utils.MJavaScriptInterface
//import com.mediacloud.app.newsmodule.utils.WebViewInsertHandle
//import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig
//import com.mediacloud.app.reslib.util.infalte.ImgTxtNewsFontControl
//import kotlinx.android.synthetic.main.imagetext_detailfragment.*
//import org.greenrobot.eventbus.EventBus
//import org.json.JSONArray
//import org.json.JSONObject
//import java.util.*
//import java.util.concurrent.LinkedTransferQueue
//import java.util.concurrent.ThreadPoolExecutor
//import java.util.concurrent.TimeUnit
//
//class NormalDetailFragment : BaseFragment(), DataInvokeCallBack<ArticleItemReciver>, ILikesNumUpdate, WebBrowser.ZoomTouchListener, View.OnClickListener, GivenMoneyStatus {
//
//    companion object {
//        var listHtmlData: String? = null
//        var audio_arr: String? = null
//        var video_arr: String? = null
//        const val FROM_VOD = "FROM_VOD"
//        const val FROM_MICROLIVE = "FROM_MICROLIVE"
//        const val FROM_SHANSHIPIN = "FROM_SHANSHIPIN"
//        const val Js2GroupImage = "Js2GroupImage"
//        const val WebImgClick = "webImgClick"
//        const val ANDROID_IFRAME = "android_iframe"
//        const val APPFACTORY_CLIENT_LOCAL_FONT_SRC = "APPFACTORY_CLIENT_LOCAL_FONT_SRC"
//        const val PACKAGE_FONT_SRC = "file:///android_asset/font/font.ttf"
//        const val NATIVE_STORAGE_PREFIX = "file://"
//        val iframe_vote_releationship: Map<String, String> = HashMap()
//    }
//
//    var isUseListData = false
//    var orginHTMLData: String? = null
//    var appConfig: AppConfig? = null
//    lateinit var serverConfigInfo: AppFactoryGlobalConfig.ServerAppConfigInfo
//    var catalogItem: CatalogItem? = null
//    var articleItem: ArticleItem? = null
//    var mShowSwitch: ShowSwitch? = null
//    var fromeVod = false
//    var fromMicroLive = false
//    var fromShanShiPin = false
//    var isFullScreen = false
//    var newsLikePresenter: NewsLikePresenter? = null
//    var powerStateReciver: PowerStateReciver? = null
//    var normalNewsAdControl: NormalNewsDetailControl? = null
//    var collectionController: CollectionController? = null
//    var imgTxtNewsFontControl: ImgTxtNewsFontControl? = null
//    lateinit var webViewInsertHandle: WebViewInsertHandle
//    override fun getLayoutResID(): Int {
//        return R.layout.imagetext_detailfragment
//    }
//
//
//    override fun initArgs() {
//        EventBus.getDefault().register(this)
//        catalogItem = arguments?.getParcelable("catalog")
//        articleItem = arguments?.getParcelable("data")
//        if (catalogItem == null) catalogItem = CatalogItem()
//        if (articleItem == null) articleItem = ArticleItem()
//        mShowSwitch = articleItem!!.getmShowSwitch()
//        arguments?.getBoolean(FROM_VOD, false)?.let {
//            fromeVod = it
//        }
//        arguments?.getBoolean(FROM_MICROLIVE, false)?.let {
//            fromMicroLive = it
//        }
//        arguments?.getBoolean(FROM_SHANSHIPIN, false)?.let {
//            fromShanShiPin = it
//        }
//        newsLikePresenter = if (activity is ImageTextDetailActivity) {
//            NewsLikePresenter(activity, this, (activity as ImageTextDetailActivity).likeBadgeView)
//        } else {
//            NewsLikePresenter(activity, this)
//        }
//        powerStateReciver = PowerStateReciver()
//        val powerFilter = IntentFilter()
//        powerFilter.addAction(Intent.ACTION_POWER_CONNECTED)
//        powerFilter.addAction(Intent.ACTION_POWER_DISCONNECTED)
//        activity?.registerReceiver(powerStateReciver, powerFilter)
//        normalNewsAdControl = NormalNewsDetailControl()
//        collectionController = CollectionController(activity, catalogItem, articleItem, null)
//    }
//
//    @SuppressLint("ClickableViewAccessibility")
//    override fun initView() {
//        appConfig = AppConfig(requireContext())
//        serverConfigInfo = AppFactoryGlobalConfig.getAppServerConfigInfo(requireContext())
//
//        imgTxtNewsFontControl = ImgTxtNewsFontControl(requireContext())
//        imgTxtNewsFontControl!!.setWebViewFont(mNewsContentView, imgTxtNewsFontControl!!.getWebViewFont(activity))
//        webViewInsertHandle = WebViewInsertHandle(activity, articleItem, catalogItem, mNewsContentView)
//        webViewInsertHandle.floatPlayerContainer = floatPlayerContainer
//        setJavaScriptInterface()
//        setScrollViewListener()
//        articleItem?.let { article ->
//            val openLikeBtn = article.tagsflag == 1 && serverConfigInfo.otherFunction != null && serverConfigInfo.otherFunction.support > 0
//            if (!openLikeBtn) {
//                likeContainer.visibility = View.GONE
//            } else {
//                likeContainer.visibility = View.VISIBLE
//            }
//
//            if (!TextUtils.isEmpty(listHtmlData)) {
//                isUseListData = true
//                if (article.orginDataObject == null) {
//                    article.orginDataObject = JSONObject()
//                }
//                try {
//                    article.orginDataObject.put("video_arr", JSONArray(video_arr))
//                    articleItem!!.orginDataObject.put("audio_arr", JSONArray(audio_arr))
//                } catch (e: Exception) {
//                }
//
//                webViewInsertHandle.haveVideoArray(articleItem)
//                webViewInsertHandle.haveAudioArray(articleItem)
//                showHTMLData(listHtmlData)
//                listHtmlData = null
//                video_arr = null
//                audio_arr = null
//            }
//        }
//        if (activity is ImageTextDetailActivity) AppfacBuyEnableUtils.refresh(activity, false)
//        resizeFont(appConfig!!.detailFontScaleLevel, AppConfig.zoomSize[appConfig!!.detailFontScaleLevel])
//    }
//
//    override fun success(data: ArticleItemReciver?) {
//    }
//
//    override fun fault(data: Any?) {
//    }
//
//    override fun updateLikesFault(data: Any?) {
//    }
//
//    override fun updateLikesSuccess(data: AddLikeDataInvoke.AddLikeDataReciver?) {
//    }
//
//    override fun updateLikesNum(value: Int) {
//    }
//
//    override fun zoomSmall() {
//    }
//
//    override fun zoomLarge() {
//    }
//
//    override fun onClick(v: View?) {
//    }
//
//    override fun givenMoneyStatus(state: Boolean) {
//    }
//
//    @SuppressLint("ClickableViewAccessibility")
//    private fun setScrollViewListener() {
//        mNewsdetailContent.setOnTouchListener(OnTouchListener { _, event ->
//            if (isFullScreen) return@OnTouchListener false
//            EventBus.getDefault().post(event)
//            false
//        })
//
//        mNewsdetailContent.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v: NestedScrollView?, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int ->
//            Log.e("SBSBSBSBS", "scrollY > " + scrollY + "    " + webViewInsertHandle.playerTop)
//            webViewInsertHandle.scrollY = scrollY
//            if (scrollY > webViewInsertHandle.playerTop) {
//                if (webViewInsertHandle.playerTop > 0) {
//                    if (webViewInsertHandle.videoPlayer.isPlaying()) {
//                        floatPlayerContainer.scrollTo(0, webViewInsertHandle.playerTop)
//                    } else {
//                        floatPlayerContainer.scrollTo(0, scrollY)
//                    }
//                } else {
//                    floatPlayerContainer.scrollTo(0, scrollY)
//                }
//            } else {
//                floatPlayerContainer.scrollTo(0, scrollY)
//                //滑动到下方视频不见了以后就暂停播放
//                if (scrollY + 2127 < webViewInsertHandle.playerTop) {
//                    if (webViewInsertHandle.videoPlayer.isPlaying()) {
//                        webViewInsertHandle.videoPlayer.pause()
//                        webViewInsertHandle.videoPlayer.controlBarViewControl.setVisibility(View.VISIBLE)
//                    }
//                }
//            }
//        } as NestedScrollView.OnScrollChangeListener)
//    }
//
//    @SuppressLint("SetJavaScriptEnabled")
//    private fun showHTMLData(data: String) {
//        orginHTMLData = data
//        mNewsContentView.settings.loadWithOverviewMode = true
//        mNewsContentView.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
//        mNewsContentView.settings.javaScriptEnabled = true
//        mNewsContentView.settings.setGeolocationEnabled(true)
//        mNewsContentView.settings.domStorageEnabled = true
//        mNewsContentView.requestFocus()
//        task = ParseHTMLDataTask()
//        task.executeOnExecutor(ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, LinkedTransferQueue()), data)
//    }
//
//
//    private fun setJavaScriptInterface() {
//        val mInterface = MJavaScriptInterface(requireContext(), mNewsContentView)
//        mNewsContentView.addJavascriptInterface(mInterface, WebViewFragment.GETMFSIGN)
//        mNewsContentView.addJavascriptInterface(mInterface, WebViewFragment.ANDROID)
//        val h5pay = H5PayJavaScriptInterface(requireContext())
//        mNewsContentView.addJavascriptInterface(h5pay, WebViewFragment.H5PAY)
//        mNewsContentView.addJavascriptInterface(this, Js2GroupImage)
//        mNewsContentView.addJavascriptInterface(this, ANDROID_IFRAME)
//    }
//
//    private fun resizeFont(levelIndex: Int, zoom: Int) {
//        appConfig!!.saveDetailFontScaleLevel(levelIndex)
//        val textSize = resources.getDimension(R.dimen.textsize_news_title) * (zoom / 100f)
//        mNewsTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
//        val webSettings: WebSettings = mNewsContentView.settings
//        webSettings.textZoom = zoom
//        webViewInsertHandle.resizeNativeControl()
//    }
//}